package com.example.springboot01;

import com.example.springboot01.mapper.StudentMapper;
import com.example.springboot01.mapper.StudentMapper2;
import com.example.springboot01.model.Student;
import com.example.springboot01.model.StudentSexEnum;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static java.lang.Thread.sleep;

/**
 * @Auther: zrd
 * @Date: 2022/3/16/03/16/16:49
 * @Description: com.example.springboot01
 */
@SpringBootTest
public class StudentMapperTest2 {
    @Autowired
    private StudentMapper2 studentMapper2;
//    @Test
//    public void testInsert() {
//        int oldNum=studentMapper2.getAll().size();
//        System.out.println("插入前记录数："+oldNum);
//        studentMapper2.insert(new Student("杜甫","大三","计本", StudentSexEnum.MAN));
//        int newNum=studentMapper2.getAll().size();
//        System.out.println("插入后记录数："+newNum);
//        int endNum=newNum-oldNum;
//        System.out.println("新增了"+endNum+"数据");
//    }

    @Test
    public void testSelectOne(){
        System.out.println(studentMapper2.getOne(3));
    }
    @Test
    public void testSelectAll(){
        System.out.println(studentMapper2.getAll());
    }

//    @Test
//    public void testUpdate() throws Exception{
//        int id = 1;
//        Student student = studentMapper2.getOne(id);
//        System.out.println("修改前："+student.toString());
//        studentMapper2.update(new Student(1,"小新","大二","智科",StudentSexEnum.WOMAN));
//        System.out.println("修改后："+studentMapper2.getOne(id));
//    }

    @Test
    public void testDelete(){
        long id = 1L;
        System.out.println("删除前记录数："+studentMapper2.getAll().size());
        studentMapper2.delete(id);
        System.out.println("删除后记录数"+studentMapper2.getAll().size());
    }


//    @Test
//    public void testSelectById(){
//        Student student = studentMapper2.SelectById(1l);
//        System.out.println(student.getStudentName());
//        try {
//            sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println(student.getCard());
//    }

    @Test
    public void testSelectById2() {
        System.out.println(studentMapper2.SelectById2(2l));
    }

    @Test
    public void testselectByClassId(){
        System.out.println(studentMapper2.selectByClassId(1));
    }
    @Test
    public void testselectByClassId1(){
        System.out.println(studentMapper2.selectByClassId1(1));
    }
}
